From fbd43d923ca33755f44f0f2ca82d7cf4f9360a67 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Juan=20Hern=C3=A1ndez?= Date: Thu, 8 Sep 2016 15:13:31 -0400 Subject: [PATCH] Add a test that reproduces the error of parsing home config twice. --- tests/cargotest/support/mod.rs | 5 +++++ tests/rustflags.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/tests/cargotest/support/mod.rs b/tests/cargotest/support/mod.rs index c99e8e294..fb6c7daf6 100644 --- a/tests/cargotest/support/mod.rs +++ b/tests/cargotest/support/mod.rs @@ -198,6 +198,11 @@ pub fn project(name: &str) -> ProjectBuilder { ProjectBuilder::new(name, paths::root().join(name)) } +// Generates a project layout inside our fake home dir +pub fn project_in_home(name: &str) -> ProjectBuilder { + ProjectBuilder::new(name, paths::home().join(name)) +} + // === Helpers === pub fn main_file(println: &str, deps: &[&str]) -> String { diff --git a/tests/rustflags.rs b/tests/rustflags.rs index 264c47219..ccdc6a91d 100644 --- a/tests/rustflags.rs +++ b/tests/rustflags.rs @@ -5,7 +5,7 @@ use std::io::Write; use std::fs::{self, File}; use cargotest::rustc_host; -use cargotest::support::{project, execs, paths}; +use cargotest::support::{project, project_in_home, execs, paths}; use hamcrest::assert_that; #[test] @@ -852,3 +852,29 @@ fn build_rustflags_no_recompile() { assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"), execs().with_stdout("").with_status(0)); } + +#[test] +fn build_rustflags_with_home_config() { + // We need a config file inside the home directory + let home = paths::home(); + let home_config = home.join(".cargo"); + fs::create_dir(&home_config).unwrap(); + File::create(&home_config.join("config")).unwrap().write_all(br#" + [build] + rustflags = ["-Cllvm-args=-x86-asm-syntax=intel"] + "#).unwrap(); + + // And we need the project to be inside the home directory + // so the walking process finds the home project twice. + let p = project_in_home("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("build").arg("-v"), + execs().with_status(0)); +} -- 2.30.2